// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   Responsible.java

package include.nseer_cookie;

import include.nseer_db.nseer_db;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class Responsible
{

	public Responsible()
	{
	}

	public static String getString(nseer_db db, String table_name, String describe)
	{
		String file_id_chain = "";
		try
		{
			List rsList = new ArrayList();
			String sql = (new StringBuilder("select file_id,category_id from ")).append(table_name).append(" where describe1 like '%").append(describe).append("%'").toString();
			for (ResultSet rs = db.executeQuery(sql); rs.next(); rsList.add(rs.getString("category_id")))
				rsList.add(rs.getString("file_id"));

			for (int i = 0; i < rsList.size(); i++)
				if (file_id_chain.indexOf((new StringBuilder(",")).append((String)rsList.get(i)).append(",").toString()) == -1)
				{
					file_id_chain = (new StringBuilder(String.valueOf(file_id_chain))).append((String)rsList.get(i)).append(",").toString();
					i++;
					if (file_id_chain.indexOf(getFileId(db, table_name, (String)rsList.get(i))) == -1)
						file_id_chain = (new StringBuilder(String.valueOf(file_id_chain))).append(getFileId(db, table_name, (String)rsList.get(i))).toString();
				} else
				{
					i++;
				}

		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
		return (new StringBuilder(",")).append(file_id_chain).toString();
	}

	private static String getFileId(nseer_db db, String table_name, String parent_category_id)
	{
		String file_id_temp = "";
		try
		{
			List rsList = new ArrayList();
			String sql = (new StringBuilder("select file_id,category_id from ")).append(table_name).append(" where parent_category_id='").append(parent_category_id).append("'").toString();
			for (ResultSet rs = db.executeQuery(sql); rs.next(); rsList.add(rs.getString("category_id")))
				rsList.add(rs.getString("file_id"));

			for (int i = 0; i < rsList.size(); i++)
			{
				file_id_temp = (new StringBuilder(String.valueOf(file_id_temp))).append((String)rsList.get(i)).toString();
				file_id_temp = (new StringBuilder(String.valueOf(file_id_temp))).append(",").append(getFileId(db, table_name, (String)rsList.get(++i))).toString();
			}

		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
		return file_id_temp;
	}
}
